(function() {
    if (app.documents.length === 0) {
        alert("请先打开一个文档。");
        return;
    }

    var doc = app.activeDocument;
    var sel = app.selection;
    if (sel.length === 0) {
        alert("当前没有选中任何对象。");
        return;
    }

    function listChildren(obj, indent) {
        indent = indent || "";
        var info = indent + obj.constructor.name + "\n";
        try {
            if (obj.allPageItems && obj.allPageItems.length > 0) {
                for (var i = 0; i < obj.allPageItems.length; i++) {
                    info += listChildren(obj.allPageItems[i], indent + "  ");
                }
            }
        } catch(e) {}
        return info;
    }

    var content = "";
    for (var i = 0; i < sel.length; i++) {
        content += "=== 选中对象 " + i + " ===\n" + listChildren(sel[i], "  ");
    }

    // 在当前页面生成一个文本框显示
    var page = doc.layoutWindows[0].activePage;
    var tb = page.textFrames.add({
        geometricBounds: [20, 20, 400, 300], // 上、左、下、右
        contents: content
    });
    tb.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;
    tb.strokeWeight = 0;
})();
